/****************************************
 ****************************************
 **   This document written by CTonk.  **
 **         ctonk@hotmail.com          **
 ****************************************
 ****************************************/

#include< stdio.h >
#include< iostream >
#include< io.h >
#include< time.h >

#define FILE_DATA _finddata_t

FILE_DATA ReturnFile( char* );
void FindFiles( char* );
void PrintStructure( _finddata_t );

#define FILE "C:/Documents and Settings/ChristopherM/Desktop/Code/VB_stuff/"

int main()
{
	long hFile;
	FILE_DATA data;
	char* string = new char[500];
	strcpy( string, FILE );
	strcat( string, "*.*" );

	if( (hFile = (long)_findfirst( string , &data )) == -1L )
	{
		printf( "No " );
		printf( "%s", string );
		printf( " files in current directory!\n" );
	}
	else
	{	
		printf( "%s:\n", string );
		printf( "\nSUB HID SYS RDO ARC  FILE         DATE %25c SIZE\n", ' ' );
		printf( "--- --- --- --- ---  ----         ---- %25c ----\n", ' ' );

		while ( _findnext( hFile, &data ) == 0 )
		{
			char* it = new char[100];
			strcpy( it, FILE );
			strcat( it, data.name );

			PrintStructure( data );

			//remove( it );
			delete [] it;
		}
	}


	delete [] string;
	return 0;
}

FILE_DATA ReturnFile( char* string)
{
	struct FILE_DATA it;
	long Hfile;

	if ( (Hfile = (long)_findfirst( string, & it )) == -1L )
		printf( "No files with \"%s\" found! Returning NULL\n", string );

	return it;
}

void FindFiles( char* string )
{
	struct FILE_DATA data;
	long hFile;

	if( (hFile = (long)_findfirst( string , & data )) == -1L )
	{
		printf( "No " );
		printf( "%s", string );
		printf( " files in current directory!\n" );
	}
	else
	{
		printf( "Listing of " );
		printf( "%s", string );
		printf( " files:\n" );
		printf( "\nSUB HID SYS RDO ARC  FILE         DATE %25c SIZE\n", ' ' );
		printf( "--- --- --- --- ---  ----         ---- %25c ----\n", ' ' );
		
		PrintStructure( data );

			while( _findnext( hFile, &data ) == 0 )
				PrintStructure( data );


			_findclose( hFile );
			printf( "\n\n\n" );
	}
}

void PrintStructure( FILE_DATA data )
{
	printf( ( data.attrib & _A_SUBDIR ) ? " Y  " : " N  " );
	printf( ( data.attrib & _A_HIDDEN ) ? " Y  " : " N  " );
	printf( ( data.attrib & _A_SYSTEM ) ? " Y  " : " N  " );
	printf( ( data.attrib & _A_RDONLY ) ? " Y  " : " N  " );
	printf( ( data.attrib & _A_ARCH )   ? " Y  " : " N  " );
	printf( " %-12s %.24s  %9ld\n",
		data.name, ctime( &( data.time_write ) ), data.size );
	return;
}